package com.itheima.bos.service.system.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.bos.dao.system.PermissionRepository;
import com.itheima.bos.domain.system.Permission;
import com.itheima.bos.domain.system.User;
import com.itheima.bos.service.system.IPermissionService;
@Service
@Transactional
public class PermisssionServiceImpl implements IPermissionService {
	
	@Autowired
	private PermissionRepository permissionRepository;
	
	@Override
	public List<Permission> findbyUser(User user) {
		
		if (user.getUsername().equals("admin")) {
			//根据报表中可以得到,admin没有设置权限和角色,所以都可以访问,即返回所有的权限,都可以访问
			return permissionRepository.findAll();
		}else {
			//根据用户查询对应的权限
			return permissionRepository.findAll(user.getId());
		}
		
	}

	@Override
	public List<Permission> findAll() {
		
		return permissionRepository.findAll();
		
	}

	@Override
	public void save(Permission model) {
		permissionRepository.save(model);
		
	}

}
